package com.dp.factory.factory_method.factory;

import com.dp.factory.simple_factory.service.impl.DiscountFreeGoods;
import com.dp.factory.simple_factory.service.impl.SmallGiftFreeGoods;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Ruomeng
 * @Date: 2024/11/26
 * @Description : design-pattern
 * 工厂的工厂，用来创建工厂类对象
 * @Version: 1.0
 */
public class FreeGoodsFactoryMap {

    // 创建map, 保存工厂对象
    private static final Map<Integer, FreeGoodsFactory> cachedFactories = new HashMap<>();

    static {
        cachedFactories.put(1, DiscountFreeGoods::new);
        cachedFactories.put(3, SmallGiftFreeGoods::new);
    }

    public static FreeGoodsFactory getParserFactory(Integer type) {
        if (type.equals(1)) {
            FreeGoodsFactory freeGoodsFactory = cachedFactories.get(1);
            return freeGoodsFactory;
        } else if (type.equals(3)){
            FreeGoodsFactory freeGoodsFactory = cachedFactories.get(3);
            return freeGoodsFactory;
        }
        return null;
    }

}
